using Gtk;
using MySql.Data.MySqlClient;
using System;
using System.Data;
using System.Globalization;
using System.Reflection;

using Serpis;
using PArticulo;


public partial class MainWindow : Gtk.Window
{
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		
		miTreeView.Init(AppDbConnection.Instance.DbConnection, entrySelect.Text);
		
		findAction.Activated += delegate {
			miTreeView.Refresh(entrySelect.Text);
		};
		
		editAction.Activated += delegate {
		
			Articulo articulo = new Articulo();
			//articulo.Nombre = "articulo " + DateTime.Now;
			articulo.Precio = 1;
			articulo.Categoria = 1;
			

			ArticuloView articuloView = new ArticuloView();
			
			Controller controller = new Controller(articulo, articuloView);
			controller.Refresh();
			
			articuloView.SaveAction.Activated += delegate {
				//controller.Update();
				
				foreach (PropertyInfo propertyInfo in articulo.GetType().GetProperties())
					Console.WriteLine("{0}={1}", propertyInfo.Name, propertyInfo.GetValue(articulo, null));
				
				articuloView.Destroy();
				
			};
		};
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}
